package com.javasm.adminapi.module.activity.controller;



import com.github.pagehelper.PageInfo;
import com.javasm.adminapi.module.activity.entity.AmActivity;
import com.javasm.adminapi.module.activity.service.AmActivityGoodsService;
import com.javasm.adminapi.common.R;
import com.javasm.adminapi.module.activity.service.AmActivityService;
import com.javasm.adminapi.module.activity.service.AmApiActivityService;
import com.javasm.adminapi.module.activity.vo.searchVo;
import com.javasm.adminapi.module.aftersalesbase.vo.SearchVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 活动管理-促销活动申请(AmActivity)表控制层
 *
 * @author makejava
 * @since 2025-10-15 14:40:02
 */
@RestController
@RequestMapping("/amActivity")
public class AmActivityController {

    @Resource
    AmApiActivityService amApiActivityService;
    @Resource
    AmActivityGoodsService amActivityGoodsService;

    @Resource
    AmActivityService amActivityService;
    @GetMapping("/page")
    public R page(searchVo vo){//查数据
       PageInfo<AmActivity> pageInfo = amApiActivityService.listByPage(vo);
       return R.ok(pageInfo);
    }

    @DeleteMapping("/del/{ids}")
    public R deleteByIds(@PathVariable Integer[] ids){//提取url路径的参数值

        amApiActivityService.deleteByIds(ids);

        //创建自定义返回对象
        Map<String, Object> result = new HashMap<>();
        result.put("success", true);
        result.put("message", "删除成功");
        result.put("deletedIds", Arrays.asList(ids));

        return R.ok(result);
    }

    @PostMapping("/save/update")
    public R savePrUpdate(AmActivity amActivity){
        amApiActivityService.saveOrUpdate(amActivity);
        return R.ok();
    }

    @PutMapping("/updateStatus/{id}")
    public R updateStatus(@RequestParam("ids") List<Integer> ids,
                          @RequestParam("status") Integer status){
        amActivityService.updateStatus(ids, status);
        return R.ok();


    }


}

